
/**		
 * 
 *	uk.co.lmfm.guppy.controller.CreateWorkspaceCommand
 *	
 *	@version 1.00 | Jan 20, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.controller 
{
	import uk.co.lmfm.guppy.model.LibraryProxy;
	import uk.co.lmfm.guppy.model.SettingsProxy;
	import uk.co.lmfm.guppy.model.WorkspaceProxy;

	import org.osflash.thunderbolt.Logger;
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;

	import flash.filesystem.File;

	/**
	 * CreateWorkspaceCommand
	 */
	public class CreateWorkspaceCommand extends SimpleCommand implements ICommand 
	{
		override public function execute(notification : INotification) : void
		{
			super.execute(notification);
			
			var workspace : File = notification.getBody() as File;
			
			var workspaceProxy : WorkspaceProxy = facade.retrieveProxy(WorkspaceProxy.NAME) as WorkspaceProxy;			var libraryProxy : LibraryProxy = facade.retrieveProxy(LibraryProxy.NAME) as LibraryProxy;
			var sqlProxy : SettingsProxy = facade.retrieveProxy(SettingsProxy.NAME) as SettingsProxy;
			
			if(workspaceProxy.isWorkspaceDirectory(workspace))
			{
				Logger.error("This folder is already a workspace, would you like to reconfigure it?");
			}
			else
			{
				Logger.info("Create workspace: " + workspace.nativePath);
				
				workspaceProxy.createWorkspace(workspace, sqlProxy.readSettings(), libraryProxy.config);
			}
		}
	}
}
